/* Copyright (c) 2004-2024 Peigen.info. All rights reserved. */

package info.peigen.hotpot.component.gateway.dianlan.protocol.passive;

import info.peigen.hotpot.component.gateway.dianlan.annotations.DianlanProtocol;
import info.peigen.hotpot.component.gateway.dianlan.facade.enums.DianlanTransStopDetail;
import info.peigen.hotpot.component.gateway.dianlan.facade.enums.DianlanTransType;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import lombok.experimental.FieldDefaults;
import lombok.experimental.SuperBuilder;

import static info.peigen.hotpot.component.gateway.dianlan.annotations.DianlanProtocol.DianlanProtocolDataType.*;

/**
 * <b>(DianlanTransInformation)</b>
 * <p>
 * 交易记录
 * 充电桩在网络正常情况下，主运发送结算账单，直到运营平台响应成账单上传成功，收到账单结
 * 算成功，本账单在充电桩本地删除。每次接收到启机命令并已执行启机过程，无论启机成功与
 * 否，都需在订单结束充电后生成账单上传
 * 帧类型码 0x3B(59)
 * 序列号域 8001
 * 数据长度 A2(162)
 * 帧校验域 388C
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2022/8/19
 */
@SuperBuilder
@Data
@NoArgsConstructor
@AllArgsConstructor
@FieldDefaults(level = AccessLevel.PRIVATE)
@Accessors(chain = true)
public class DianlanTransInformation {
    /** 交易流水号 */
    @DianlanProtocol(length = 16, start = 0, end = 16, dataType = BCD)
    String transNo;
    /** 桩编码 */
    @DianlanProtocol(length = 7, start = 16, end = 23, dataType = BCD)
    String stubNo;
    /** 充电枪号 */
    @DianlanProtocol(length = 1, start = 23, end = 24, dataType = BCD)
    String chargingPortNo;
    /** 开始时间 */
    @DianlanProtocol(length = 7, start = 24, end = 31, dataType = TIME)
    String startTime;
    /** 结束时间 */
    @DianlanProtocol(length = 7, start = 31, end = 38, dataType = TIME)
    String endTime;

    /** 尖单价 精确到小数点后五位（尖电费+尖服务费，见费率帧） */
    @DianlanProtocol(length = 4, start = 38, end = 42, dataType = BIN)
    String needleUnitPrice;
    /** 尖电量 精确到小数点后四位 */
    @DianlanProtocol(length = 4, start = 42, end = 46, dataType = BIN)
    String needleCurrent;
    /** 计损尖电量 精确到小数点后四位 */
    @DianlanProtocol(length = 4, start = 46, end = 50, dataType = BIN)
    String lossNeedleCurrent;
    /** 尖金额 精确到小数点后四位 */
    @DianlanProtocol(length = 4, start = 50, end = 54, dataType = BIN)
    String needleAmount;

    /** 峰单价 精确到小数点后五位（峰电费+峰服务费） */
    @DianlanProtocol(length = 4, start = 54, end = 58, dataType = BIN)
    String peakUnitPrice;
    /** 峰电量 精确到小数点后四位 */
    @DianlanProtocol(length = 4, start = 58, end = 62, dataType = BIN)
    String peakCurrent;
    /** 计损峰电量 精确到小数点后四位 */
    @DianlanProtocol(length = 4, start = 62, end = 66, dataType = BIN)
    String lossPeakCurrent;
    /** 峰金额 精确到小数点后四位 */
    @DianlanProtocol(length = 4, start = 66, end = 70, dataType = BIN)
    String peakAmount;

    /** 平单价 精确到小数点后五位（平电费+平服务费） */
    @DianlanProtocol(length = 4, start = 74, end = 78, dataType = BIN)
    String flatUnitPrice;
    /** 平电量 精确到小数点后四位 */
    @DianlanProtocol(length = 4, start = 78, end = 82, dataType = BIN)
    String flatCurrent;
    /** 计损平电量 精确到小数点后四位 */
    @DianlanProtocol(length = 4, start = 82, end = 86, dataType = BIN)
    String lossFlatCurrent;
    /** 平金额 精确到小数点后四位 */
    @DianlanProtocol(length = 4, start = 86, end = 90, dataType = BIN)
    String flatAmount;

    /** 谷单价 精确到小数点后五位（谷电费+谷服务费） */
    @DianlanProtocol(length = 4, start = 90, end = 94, dataType = BIN)
    String valleyUnitPrice;
    /** 谷电量 精确到小数点后四位 */
    @DianlanProtocol(length = 4, start = 94, end = 96, dataType = BIN)
    String valleyCurrent;
    /** 计损谷电量 精确到小数点后四位 */
    @DianlanProtocol(length = 4, start = 96, end = 100, dataType = BIN)
    String lossValleyCurrent;
    /** 谷金额 精确到小数点后四位 */
    @DianlanProtocol(length = 4, start = 100, end = 104, dataType = BIN)
    String valleyAmount;


    /** 电表总起值 精确到小数点后四位 */
    @DianlanProtocol(length = 5, start = 104, end = 109, dataType = BIN)
    String                 totalStart;
    /** 电表总止值 精确到小数点后四位 */
    @DianlanProtocol(length = 5, start = 109, end = 114, dataType = BIN)
    String                 totalStop;
    /** 总电量 精确到小数点后四位 */
    @DianlanProtocol(length = 4, start = 114, end = 118, dataType = BIN)
    String                 totalCurrent;
    /** 计损总电量 精确到小数点后四位 */
    @DianlanProtocol(length = 4, start = 118, end = 122, dataType = BIN)
    String                 lossTotalCurrent;
    /** 消费金额 精确到小数点后四位 */
    @DianlanProtocol(length = 4, start = 122, end = 126, dataType = BIN)
    String                 consumeAmount;
    /** 电动汽车唯一标识 VIN */
    @DianlanProtocol(length = 17, start = 126, end = 143, dataType = ASCII)
    String                 vin;
    /** 交易标识 */
    @DianlanProtocol(length = 1, start = 143, end = 144, dataType = ENUM)
    DianlanTransType       transType;
    /** 交易时间 */
    @DianlanProtocol(length = 7, start = 144, end = 151, dataType = TIME)
    String                 transTime;
    /** 交易标识 */
    @DianlanProtocol(length = 1, start = 151, end = 152, dataType = ENUM)
    DianlanTransStopDetail stopReason;
    /** 物理卡号 显示在屏幕上，不足 8 位补零 */
    @DianlanProtocol(length = 8, start = 152, end = 160, dataType = BIN)
    String                 physicsCardNo;

}